<template>
  <div class="present">
    <van-overlay :show="show" class-name="bgcolor">
        <div class="wrapper" @click.stop>
          <div class="block" />
        </div>
      </van-overlay>
    <nav>
      <div class="twonav">
        <router-link :to="{ name: 'home' }"> <span></span></router-link>
        <p>看漫漫画</p>
      </div>
    </nav>
    <div
      class="topimg"
      v-lazy:background-image="
         chdetails.horizontal_cover + '@760w_380h.jpg' "
    >
      <div>
        <h3>{{ chdetails.title }}</h3>
        <p>
          <span v-for="(item, index) in chdetails.author_name" :key="index"
            >{{ item }}.</span
          >
          <span v-for="item in chdetails.styles2" :key="item.id">{{
            item.name
          }}</span>
          MC{{ chdetails.id }}
        </p>
      </div>
    </div>
    <div class="content">
      <div class="enshrine">
        <div class="enleft">
          <span>
            <img src="../../assets/star-smile-fill.svg" alt="" />
          </span>
          <span>追漫</span>
        </div>
        <!-- <router-link :to="{name:'content',query:{id:`${oneid}`}}"><button>看第001话</button></router-link> -->
        <div class="enright">
          <router-link :to="{ name: 'content', query: { id: `${myone.id}`,tilid:`${chdetails.id}` } }"
            ><button>看第{{myone.short_title}}话</button></router-link>
        </div>
      </div>
      <div class="stories">
        <h4 v-if="chdetails.is_finish == 0">连载中</h4>
        <h4 v-if="chdetails.is_finish == 1">已完结</h4>
        <p>
          <span class="back">{{ chdetails.classic_lines }}</span>
          <!-- <span class="downlogo"></span> -->
        </p>
      </div>
      <div class="chapters">
        <div class="chapterstop">
          <h3>全部章节({{ chdetails.last_ord }})</h3>
          <div class="clearfix" @click="playRev">
            <span v-if="!isBol">升序</span>
            <span v-if="isBol">降序</span>
            <span >
              <img :class="{'act':isBol}" src="../../assets/下载.svg" alt="" />
            </span>
          </div>
        </div>
        <ul :class="{mystyle:isShow}">
          <router-link
            v-for="(item) in chreverse"
            :key="item.id"
            :to="{ name: 'content', query: { id: item.id,num:item.short_title,title:chdetails.title ,tilid:`${chdetails.id}`} }"
          >
            <li>{{ item.short_title}}</li></router-link>
          <!-- <a href="#" v-for="(item, index) in chdetails.ep_list" :key="item.id"
            ><li>{{ index + 1 }}</li></a
          > -->
          <div v-if="!isShow">
            <button @click="isShow=true">...</button>
          </div>
        </ul>
      </div>
      <div class="discuss">
        <h3>讨论区({{ myacount }})</h3>
        <div class="srocll">
          <ul>
            <li v-for="item in chreviews.replies" :key="item.rpid">
              <div class="disUsers clearfix">
                <span>
                  <img :src="item.member.avatar" alt="" />
                </span>
                <div>
                  <p>{{ item.member.uname }}</p>
                  <p>{{ item.reply_control.time_desc }}</p>
                </div>
              </div>
              <div class="review">
                <p>
                  {{ item.content.message }}
                </p>
              </div>
            </li>
          </ul>
        </div>
      </div>
      <div class="groom">
        <h3>猜你喜欢</h3>
        <ul>
          <li v-for="item in chdrelevant" :key="item.season_id">
            <router-link
              :to="{ name: 'present', query: { id: item.season_id } }"
            >
              <div class="img">
                <img v-lazy="item.vertical_cover" alt="" />
              </div>
            </router-link>

            <div class="wrod">
              <p>{{ item.title }}</p>
              <span>
                <i v-if="item.is_finish == 0">更新至</i
                ><i v-if="item.is_finish == 1">[完结]共</i>
                {{ item.last_short_title | add }}
              </span>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
import { get } from "@/http/request";

export default {
  name: "present",
  inject:['reload'],
  data() {
    return {
      chdetails: {},
      chreverse:{},
      chreviews: {},
      chdrelevant: {},
      myacount: 0,
      myone:{},
      myid:0,
      isShow: false,
      isBol:false,
      show: true,
    };
  },
  methods: {
    async details(data) {
      await get("https://apis.netstart.cn/mbcomic/ComicDetail", data).then(
        (res) => {
          console.log(res);
          this.chdetails = res.data;
          this.chreverse=res.data.ep_list.reverse();
          this.myone=this.chreverse[0]
        }
      );
    },
    async review(data) {
      await get("https://apis.netstart.cn/mbcomic/reply", data).then((res) => {
        // console.log(res);
        this.chreviews = res.data;
        this.myacount = this.chreviews.page.acount;
      });
    },
    async drelevant(data) {
      await get("https://apis.netstart.cn/mbcomic/Recommend", data).then(
        (res) => {
          // console.log(res);
          this.chdrelevant = res.data;
        }
      );
    },
    playRev(){
      if(this.isBol){
        this.isBol=false;
        this.chreverse=this.chreverse.reverse();
          this.myone=this.chreverse[0]
      }else{
        this.isBol=true;
        this.chreverse=this.chreverse.reverse();
          this.myone=this.chreverse[0]
      }
    },
    init(){
      this.myid = this.$route.query.id;
      this.details({ comic_id: this.myid });
    this.review({ oid: this.myid });
    this.drelevant({ comic_id: this.myid });
    },
    
  },
  created() { 
    
    this.init()
  },
  updated(){
    // this.myid = this.$route.query.id;
  },
  filters: {
    add(value) {
      if (parseInt(value)) {
        value = value + "话";
      }
      return value;
    },
  },
  
  watch:{
    
    chdetails(newimg, oldimg) {
      if (oldimg == null) {
        this.show =true
      } else if (newimg) {
        this.show = false;
      }
    },
    $route(to) {
      if (this.$route.name == "present") {
        // this.myid=this.$route.query.id
        this.init()
      }
    },
  },
  
};
</script>

<style lang="scss" scoped>
.mystyle {
  height: auto !important;
}
.act{
  transform: rotate(180deg);
}
.bgcolor{
  background-color: #fcfbfb;
  z-index: 1000;
}
.wrapper {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  .block {
    width: 120px;
    height: 120px;
    background-image: url(../../assets/1441607667576727.gif);
    background-size: cover;
    background-position-x: center;
    background-color: #fff;
  }
}
.present {
  width: 100%;
  margin: 0 auto;

  nav {
    position: fixed;
    top: 0%;
    left: 0;
    background-color: #fff;
    padding-left: 10px;
    width: 100%;
    height: 46px;
    border-bottom: 1px solid #ccc;
    box-sizing: border-box;
    z-index: 1001;
    .twonav {
      width: 100%;
      height: 46px;
      line-height: 46px;
      position: relative;
      span {
        position: absolute;
        top: 15px;
        left: 5px;
        display: block;
        width: 12px;
        height: 12px;
        border-left: 3px solid #ccc;
        border-top: 3px solid #ccc;
        transform: rotate(-45deg);
      }
      p {
        
        font-size: 16px;
      }
    }
    a,
    a:hover,
    a:focus {
      -webkit-tap-highlight-color: transparent;
    }
  }
  .topimg {
    width: 100%;
    // height: 100%;
    background-image: url(../../assets/1441607669615589.gif);
    background-size: cover;
    padding-top: 56%;
    background-repeat: no-repeat;
    background-position: 50%;
    position: relative;
    div {
      position: absolute;
      z-index: 100;
      bottom: 5px;
      left: 5px;
      text-align: left;
      color: #fff;
      h3 {
        font-size: 20px;
        text-shadow: 0 1px 2px rgb(0 0 0 / 50%);
      }
      p {
        font-size: 12px;
        color: #fffffee6;
        text-shadow: 0 1px 2px rgb(0 0 0 / 50%);
        span {
          margin-right: 5px;
        }
      }
    }
  }
  .content {
    width: 100%;
    padding: 10px;
    margin-top: 5px;
    .enshrine {
      width: 100%;
      height: 40px;
      display: flex;
      justify-content: space-between;
      align-content: center;
      .enleft {
        height: 40px;
        line-height: 40px;
        span {
          margin-right: 10px;
          font-size: 18px;
          img {
            width: 36px;
            height: 36px;
            vertical-align: middle;
          }
        }
      }
      .enright {
        font-size: 14px;
        button {
          background-color: #fb7299;
          color: #fff;
          border: 0;
          padding: 1px 6px;
          width: 200px;
          height: 40px;
          border-radius: 20px;
        }
      }
    }
    .stories {
      margin-top: 20px;
      width: 100%;
      text-align: left;
      h4 {
        font-size: 16px;
        margin-bottom: 5px;
      }
      p {
        position: relative;
        color: #999;
        width: 100%;
        font-size: 12px;

        .back {
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
        .downlogo {
          // position: absolute;
          // bottom: 0;
          // right: 10px;
          display: block;
          width: 6px;
          height: 6px;
          border-left: 1px solid #999;
          border-bottom: 1px solid #999;
          transform: rotate(-45deg);
          //   background-color: red;
          //   z-index: 10000;
        }
      }
    }
    .chapters {
      width: 100%;
      text-align: left;
      margin-top: 20px;
      .chapterstop {
        margin: 10px 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        h3 {
          font-size: 16px;
        }
        div {
          font-size: 12px;
          align-self: center;
          span {
            float: left;
            img {
              width: 16px;
              height: 16px;
              // transform: rotate(180deg);
            }
          }
        }
      }
      ul {
        width: 100%;
        height: 91px;
        overflow: hidden;
        display: flex;
        flex-wrap: wrap;
        position: relative;
        a {
          width: 25%;
          padding: 3px;

          li {
            border: 1px solid #ccc;
            font-size: 14px;
            display: inline-block;
            width: 100%;
            padding: 2px;
            overflow: hidden;
            color: #212121;
            text-align: center;
            line-height: 30px;
            box-sizing: border-box;
            border-radius: 5px;
          }
        }
        div {
          width: 25%;
          padding: 3px;
          position: absolute;
          right: 0;
          bottom: 0px;
          button {
            width: 100%;
            border: 1px solid #ccc;
            font-size: 14px;
            // display: inline-block;
            width: 100%;
            padding: 2px;
            overflow: hidden;
            color: #212121;
            text-align: center;
            line-height: 30px;
            box-sizing: border-box;
            border-radius: 5px;
            background-color: #fff;
          }
        }
      }
    }
    .discuss {
      width: 100%;

      margin: 10px 0;
      text-align: left;
      // overflow: hidden;
      h3 {
        font-size: 16px;
        margin: 10px 0;
      }
      .srocll {
        width: 100%;
        overflow-y: scroll;

        ul {
          width: 1600%;
          display: flex;
          flex-wrap: nowrap;
          white-space: nowrap;
          padding-bottom: 5px;
          li {
            width: 6%;
            border: 1px solid #ccc;
            padding: 10px;
            border-radius: 5px;
            margin-right: 10px;
            .disUsers {
              width: 100%;
              span {
                float: left;
                margin-right: 10px;
                img {
                  width: 32px;
                  height: 32px;
                  border-radius: 16px;
                }
              }
              div {
                width: 100%;
                font-size: 12px;
                color: #999;
                display: block;
                p {
                  width: 100%;
                  margin: 5px 0;
                }
              }
            }
            .review {
              width: 100%;
              margin-top: 5px;
              font-size: 12px;
              // display: block;
              padding-right: 10px;
              p {
                overflow: hidden;
                white-space: pre-wrap;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 3;
                -webkit-box-orient: vertical;
              }
            }
          }
        }
      }
    }
    .groom {
      width: 100%;
      text-align: left;
      h3 {
        font-size: 16px;
      }
      ul {
        width: 100%;
        display: flex;
        justify-content: space-between;
        flex-flow: wrap;
        font-size: 12px;
        color: #999;
        padding: 10px;
        li {
          width: 30%;
          a {
            width: 100%;
            .img {
              width: 100%;
              img {
                width: 100%;
              }
            }
          }

          .wrod {
            width: 100%;
            text-align: left;
            margin: 5px 0;
            p {
              font-size: 14px;
              color: #222;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
            }
            span {
              display: block;
            }
          }
        }
        li:nth-child(n + 4) {
          margin-top: 10px;
        }
      }
    }
  }
}
</style>